package cn.dgut.training.dto;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RoleDTO extends BaseDTO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "角色名称")
    private String name;

    @ApiModelProperty(value = "角色描述")
    private String des;

    @ApiModelProperty(value = "是否启用")
    private Boolean enabled;


    public QueryWrapper getWrapper(RoleDTO roleDTO){

        QueryWrapper queryWrapper=new QueryWrapper();

        if (!StringUtils.isEmpty(name)) {
            queryWrapper.like("name",name);
        }

        if(!StringUtils.isBlank(roleDTO.getOrderBy())){
            if("desc".equals(roleDTO.getSort())){
                queryWrapper.orderByDesc(roleDTO.getOrderBy());
            }else {
                queryWrapper.orderByAsc(roleDTO.getOrderBy());
            }

        }

        return queryWrapper;
    }
}
